﻿////////////////////////////////////////////////////
//
// Copyright (c) 2010, Cristian Daini
// All rights reserved.
// 
// http://laharsubsample.codeplex.com/
//
////////////////////////////////////////////////////

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.IO;

namespace Chat
{
    [DataContract]
    public class DataMessage
    {
        [DataMember]
        public string source { get; set; }

        [DataMember]
        public string target { get; set; }

        [DataMember]
        public string content { get; set; }

        [DataMember]
        public byte[] someBinary { get; set; }


        public Stream ToStream()
        {
            DataContractSerializer serializer = new DataContractSerializer(typeof(DataMessage));
            MemoryStream ms = new MemoryStream();
            serializer.WriteObject(ms, this);
            ms.Position = 0;
            return ms;
        }


        static public DataMessage FromStream(Stream ms)
        {
            DataContractSerializer serializer = new DataContractSerializer(typeof(DataMessage));
            return (DataMessage)serializer.ReadObject(ms);
        }
        
    }
}
